package com.todo.biz.application.api.controller;

import com.todo.biz.application.convert.BizBaseConvert;
import com.todo.biz.application.entity.bo.BizCounterBO;
import com.todo.biz.application.service.BizCounterService;
import com.todo.biz.service.api.BizCounterApi;
import com.todo.biz.service.api.request.QueryBizCounterByBizIdRequest;
import com.todo.biz.service.api.response.BizCounterBaseResponse;
import com.todo.common.common.entity.response.BizResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/2/28 02:01
 * @description
 */
@RestController
@RequestMapping("/api/biz/counter")
@Tag(name = "服务端-计数器处理类", description = "服务端-计数器处理类")
public class BizCounterApiController implements BizCounterApi {

    @Resource
    private BizCounterService bizCounterService;

    @Override
    @Operation(summary = "根据业务id查询业务计数器")
    @PostMapping("/queryBizCounterByBizId")
    public BizResponse<List<BizCounterBaseResponse>> queryBizCounterByBizId(@RequestBody QueryBizCounterByBizIdRequest request) {
        if (request == null || request.getBizId() == null || request.getScene() == null) {
            return BizResponse.paramError();
        }
        List<BizCounterBO> bizCounterBOList = bizCounterService.queryBizCounterByBizIdAndScene(request.getBizId(), request.getScene());
        if (CollectionUtils.isEmpty(bizCounterBOList)) {
            return BizResponse.success();
        }
        return BizResponse.success(BizBaseConvert.convertToBizCounterBaseResponseList(bizCounterBOList));
    }
}
